package io.renren.modules.sys.customer.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import io.renren.modules.sys.customer.dao.BtCategroyManageDao;
import io.renren.modules.sys.customer.entity.BtCategroyManageEntity;
import io.renren.modules.sys.customer.service.BtCategroyManageService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("btCategroyManageService")
public class BtCategroyManageServiceImpl extends ServiceImpl<BtCategroyManageDao, BtCategroyManageEntity> implements BtCategroyManageService {

    @Override
    public List<BtCategroyManageEntity> queryList(Map<String, Object> params){
        List<BtCategroyManageEntity> deptList =
                this.selectList(new EntityWrapper<BtCategroyManageEntity>());

        for(BtCategroyManageEntity sysDeptEntity : deptList){
            BtCategroyManageEntity parentDeptEntity =  this.selectById(sysDeptEntity.getPid());
            if(parentDeptEntity != null){
                sysDeptEntity.setParentName(parentDeptEntity.getName());
            }
        }
        return deptList;
    }
    @Override
    public List<Long> queryCateMagIdList(Long pid){
        return baseMapper.queryCateMagIdList(pid);
    }

    /**
     *这段是他妈的写死的，没想出好的办法。
     */
    public Map<String,Object> getfenlei(Long pid){
        Map<String,Object> backdata = new HashMap<>();
        BtCategroyManageEntity sub = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("id",pid));
        List<BtCategroyManageEntity> subsubchild =null ;
        List<BtCategroyManageEntity> subchild = null;
        BtCategroyManageEntity tmbean =null;
        switch (sub.getCatatype()){
            case  "1": //国内
                //获取主题
                subsubchild = new ArrayList<>();
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","1,1"));
                for (BtCategroyManageEntity hs :subchild){
                    List<BtCategroyManageEntity> tempsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",hs.getId()));
                    for(BtCategroyManageEntity tsss:tempsubsubchild){
                        List<BtCategroyManageEntity> tempsubsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tsss.getId()));
                        subsubchild.addAll(tempsubsubsubchild);
                    }

                }
                backdata.put("themecatag",subsubchild);
                //获取举办城市
                subsubchild = new ArrayList<>();
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","1,2"));
                for (BtCategroyManageEntity hs :subchild){
                    List<BtCategroyManageEntity> tempsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",hs.getId()));
                    for(BtCategroyManageEntity tsss:tempsubsubchild){
                        List<BtCategroyManageEntity> tempsubsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tsss.getId()));
                        subsubchild.addAll(tempsubsubsubchild);
                    }
                }
                backdata.put("zbcitycatag",subsubchild);
                //获取营期
                subsubchild = new ArrayList<>();
                tmbean = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","1,4"));
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tmbean.getId()));
                subsubchild.addAll(subchild);
                backdata.put("yingqicatag",subsubchild);
                //招生对象
                subsubchild = new ArrayList<>();
                tmbean = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","1,3"));
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tmbean.getId()));
                subsubchild.addAll(subchild);
                backdata.put("zsdxcatagag",subsubchild);
                break;
            case  "2": //国际
                //获取主题
                subsubchild = new ArrayList<>();
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,1"));
                for (BtCategroyManageEntity hs :subchild){
                    List<BtCategroyManageEntity> tempsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",hs.getId()));
                    subsubchild.addAll(tempsubsubchild);
                }
                backdata.put("themecatag",subsubchild);
                //获取举办城市
                subsubchild = new ArrayList<>();
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,2"));
                for (BtCategroyManageEntity hs :subchild){
                    List<BtCategroyManageEntity> tempsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",hs.getId()));
                    subsubchild.addAll(tempsubsubchild);
                }
                backdata.put("zbcitycatag",subsubchild);
                //获取营期
                subsubchild = new ArrayList<>();
                tmbean = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,4"));
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tmbean.getId()));
                subsubchild.addAll(subchild);
                backdata.put("yingqicatag",subsubchild);
                //招生对象
                subsubchild = new ArrayList<>();
                tmbean = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,3"));
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tmbean.getId()));
                subsubchild.addAll(subchild);
                backdata.put("zsdxcatagag",subsubchild);
                //游学国家
                subsubchild = new ArrayList<>();
                tmbean = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","2,5"));
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tmbean.getId()));
                subsubchild.addAll(subchild);
                backdata.put("yxgjcatag",subsubchild);

                break;
            case  "3": //假日
                //获取主题
                subsubchild = new ArrayList<>();
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","3,2"));
                for (BtCategroyManageEntity hs :subchild){
                    List<BtCategroyManageEntity> tempsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",hs.getId()));
                    subsubchild.addAll(tempsubsubchild);
                }
                backdata.put("themecatag",subsubchild);
                //获取举办城市
                subsubchild = new ArrayList<>();
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","3,1"));
                for (BtCategroyManageEntity hs :subchild){
                    List<BtCategroyManageEntity> tempsubsubchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",hs.getId()));
                    subsubchild.addAll(tempsubsubchild);
                }
                backdata.put("zbcitycatag",subsubchild);
                //获取营期
                subsubchild = new ArrayList<>();
                tmbean = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","3,4"));
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tmbean.getId()));
                subsubchild.addAll(subchild);
                backdata.put("yingqicatag",subsubchild);
                //招生对象
                subsubchild = new ArrayList<>();
                tmbean = this.selectOne(new EntityWrapper<BtCategroyManageEntity>().eq("catatype","3,3"));
                subchild =  this.selectList(new EntityWrapper<BtCategroyManageEntity>().eq("pid",tmbean.getId()));
                subsubchild.addAll(subchild);
                backdata.put("zsdxcatagag",subsubchild);
                break;
        }
        return backdata;
    }
}
